<template>
	<view>
		<!-- 搜索组件 -->
		<view class="search-contain">
			<my-search @myclick="gotoSearch"></my-search>
		</view>
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
			<swiper-item v-for="(item, index) in swiperList" :key="index">
				<navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id=' + item.goods_id">
					<image :src="item.image_src"></image>
				</navigator>
			</swiper-item>
		</swiper>
		<view class="nav">
			<view class="nav-item" v-for="(item, index) in cateList" :key="index" @click="jumpNav(item)">
				<image :src="item.image_src"></image>
			</view>
		</view>
		<view class="floor">
			<view class="floor-item" v-for="(item, i) in floorList" :key="i">
				<view class="item-title">
					<image :src="item.floor_title.image_src"></image>
				</view>
				<view class="item-box">
					<navigator class="box-left" :url="'/subpkg/goods_list/goods_list?' + item.product_list[0].navigator_url.split('?')[1]">
						 <!-- mode="widthFix" 高度自适应 -->
						<image :src="item.product_list[0].image_src" mode="widthFix" :style="{'width': item.product_list[0].image_width + 'rpx'}"></image>
					</navigator>
					<view class="box-right">
						<navigator v-if="productIndex !== 0" v-for="(productItem, productIndex) in item.product_list" :key="productIndex" :url="'/subpkg/goods_list/goods_list?' + productItem.navigator_url.split('?')[1]">
							<image :src="productItem.image_src"  mode="widthFix" :style="{'width': productItem.image_width + 'rpx'}"></image>
						</navigator>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import badgeMix from '@/mixins/tabbar-badge.js'
	export default {
		mixins: [badgeMix],
		data() {
			return {
				swiperList: [],
				cateList: [],
				floorList: []
			}
		},
		onLoad() {
			this.getSwiperList()
			this.getCateList()
			this.getFloorList()
		},
		methods: {
			async getSwiperList() {
				const {data: res } = await uni.$http.get('/api/public/v1/home/swiperdata')
				if(res.meta.status !== 200) return uni.$showMsg()
				this.swiperList = res.message
			},
			async getCateList() {
				const { data } = await uni.$http.get('/api/public/v1/home/catitems')
				if(data.meta.status !== 200) return uni.$showMsg()
				this.cateList = data.message
			},
			jumpNav(item) {
				if(item.name === '分类') {
					uni.switchTab({
						url: '/pages/cate/cate'
					})
				}
			},
			async getFloorList() {
				const { data } = await uni.$http.get('/api/public/v1/home/floordata')
				console.log(data)
				if(data.meta.status !== 200) return uni.$showMsg()
				this.floorList = data.message
			},
			gotoSearch() {
				uni.navigateTo({
					url: '/subpkg/search/search'
				})
			}
		}
	}
</script>

<style lang="scss">
swiper {
	height: 330rpx;
	.swiper-item ,image {
		height: 100%;
		width: 100%;
	}
}
.nav {
	display: flex;
	justify-content: space-around;
	margin: 15px 0;
	.nav-item {
		width: 20%;
		image {
			width: 100%;
			height: 160rpx;
		}
	}
}
.floor {
	.floor-item {
		margin: 20rpx 0;
		.item-title {
			image {
				height: 60rpx;
				width: 100%;
			}
		}
		.item-box {
			display: flex;
			padding-left: 10rpx;
			.box-left {
			}
			.box-right {
				display: flex;
				flex-wrap: wrap;
				justify-content: space-around;
			}
		}
	}
}
.search-contain {
	position: sticky; // 吸顶效果
	top: 0;
	z-index: 999; // 防止轮播图覆盖之上
}
</style>
